/*********************************************************
*
*  Project:      HZFlashCards
*
*  Class:        HTMLListPane
*
*  File name:    HTMLListPane.java
*
*
*    SVN:
*
*    $Rev$:
*    $Date$:
*    $LastChangedBy$:
*
*    $HeadURL$:
*
**********************************************************/

package com.eastmountain.chinese.gui;

import java.util.Vector;

import com.eastmountain.chinese.common.HTMLStrings;
import com.eastmountain.chinese.db.flashcards.records.ChineseWordProperties;

/*********************************************************
 *
 *  Class:        HTMLCharacterToWordXRFListPane
 *
 **********************************************************/

@SuppressWarnings("serial" )
public class HTMLCharacterToWordXRFListPane extends HTMLListPane {

    private Vector<ChineseWordProperties> chineseWordPropertiesGroup;

    private String[][] fieldValues;

    // TODO make the following constants

    private static String[] tdClasses = { "center", "center", "left", "right", "right" };

    public HTMLCharacterToWordXRFListPane() {

        System.out.println( "\nHTMLCharacterToWordXRFListPane() invoked\n" );

        //  EXP add table view of the data
        
        //new TableReviewListPane();

    }

    public void displayHTML( String hanZi, Vector<ChineseWordProperties> chineseWordPropertiesGroup ) {

        System.out.println( "\nHTMLReviewListPane.displayHTML() invoked\n" );

        this.chineseWordPropertiesGroup = chineseWordPropertiesGroup;

        createHTMLListPanel( "Character to Word XRF for " +  hanZi );

        String trTag = "<tr>";
        String tdEntry = "<td>";

        startHTML();

        htmlBody.append( "<table id=\"mytable\">" + HTMLStrings.nl + "<tbody>" + HTMLStrings.nl
                                        + "<caption>Character Word XRF for "
                                        + hanZi + "</caption>" + HTMLStrings.nl );

        htmlBody.append( "<tr>" + HTMLStrings.nl
                          + "    <th class=\"definition\">Word</th>" + HTMLStrings.nl
                          + "    <th class=\"definition\">PinYin</th>" + HTMLStrings.nl
                          + "    <th class=\"narrow\">Level</th>" + HTMLStrings.nl
                          + "    <th class=\"narrow\">Lesson</th>" + HTMLStrings.nl
                          + "    <th class=\"definition\">Definition</th>" + HTMLStrings.nl
                          + "</tr>" + HTMLStrings.nl );

        for ( int i = 0; i < chineseWordPropertiesGroup.size(); i++ ) {

            if ( i % 2 == 0 ) {

                trTag = "<tr class=\"alt\">";

            } else {

                trTag = "<tr>";

            }

            htmlBody.append( trTag );

            String lessonNo = Integer.toString( chineseWordPropertiesGroup.elementAt( i )
                                            .getLessonNumber() );

            tdEntry = createTDEntry( chineseWordPropertiesGroup.elementAt( i ).getChineseElement(), HTMLCharacterToWordXRFListPane.tdClasses[ 0 ] );
            htmlBody.append( tdEntry );
            tdEntry = createTDEntry( chineseWordPropertiesGroup.elementAt( i ).getPinyin(), HTMLCharacterToWordXRFListPane.tdClasses[ 1 ] );
            htmlBody.append( tdEntry );
            tdEntry = createTDEntry( chineseWordPropertiesGroup.elementAt( i ).getLevel(), HTMLCharacterToWordXRFListPane.tdClasses[ 2 ] );
            htmlBody.append( tdEntry );
            tdEntry = createTDEntry( lessonNo, HTMLCharacterToWordXRFListPane.tdClasses[ 3 ] );
            htmlBody.append( tdEntry );
            tdEntry = createTDEntry( chineseWordPropertiesGroup.elementAt( i ).getEnglish(), HTMLCharacterToWordXRFListPane.tdClasses[ 4 ] );
            htmlBody.append( tdEntry );

            htmlBody.append( "</tr>" + HTMLStrings.nl );

        }

        htmlBody.append( "</tbody>" + HTMLStrings.nl + "</table>" + HTMLStrings.nl );

        finishHTML();

    }

    private String createTDEntry( String entry, String tdClass ) {

        String tdTag;
        String tdEntry;

        tdTag = "    <td class=\"" + tdClass + "\">";

        tdEntry = tdTag + entry + "</td>" + HTMLStrings.nl;

        return tdEntry;

    }

}
